<?php 
define('MINI_RUN', true);
require 'mini.php';
Mini::checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
<title>栏目文章管理--<?=Mini::NAME?>后台管理系统</title>
<?=Mini::ADMIN_CSS?>
<style type="text/css">
a{color:blue;}
</style>
</head>
<body>
<p class="msg">&nbsp;</p>
<p>选择栏目*：<select id="classid">
<option value="null">请选择</option>
<option value="0">全部</option>
<?=Mini::getsubclass()?>
</select></p>
<p align="center" id="pagelist">
</p>
<input id="pre" type="button" disabled="disabled" value="上一页" /> <input id="next" type="button" value="下一页" disabled="disabled" />
<?=Mini::JQUERY_JS?>
<?=Mini::ADMIN_JS?>
<script type="text/javascript">
var pageArr=new Object();
var thisPage=1;
var maxSize=20;
var isload=false;
var thead='<table border="1" bordercolor="#09C" width="100%" cellpadding="3" cellspacing="0"><tr><td width="10%" align="center">ID</td><td width="55%" align="center">标题</td><td width="15%" align="center">发布者</td><td width="10%" align="center">评论</td><td width="10%" align="center">操作</td></tr>';
var tfoot="</table>";
var tnull='<tr><td align="center" class="red" colspan="5">&nbsp;</td></tr>';
$(function (){
	$("#classid").change(function(){
		var thisId=$("#classid").val();
		if(thisId=="null"){
			noplay();
			return false;
		}
		thisPage=1;
		if(pageArr[thisId+"_"+thisPage]==null){
			var result=getAction(<?=$ajaxget?>,{op:"getpagelist",classid:thisId,pageindex:thisPage,pagesize:maxSize},"获取栏目数据");
			if(result==null){
				pageArr[thisId+"_"+thisPage]=null;
			}else{
				var json=eval("("+result+")");
				pageArr[thisId+"_"+thisPage]=json;
			}				
		}
		showData(thisId+"_"+thisPage);		
	});
	$("#next").click(function(){
		var thisId=$("#classid").val();
		var nextPage=thisPage+1;
		if(pageArr[thisId+"_"+nextPage]==null){
			var result=getAction(<?=Mini::AJAX_GET?>,{op:"getpagelist",classid:thisId,pageindex:nextPage,pagesize:maxSize},"获取栏目数据");
			if(result==null){
				pageArr[thisId+"_"+nextPage]=null;
				$("#next").attr("disabled","disabled");			
				showMsg("没有下一页！","没有下一页！");				
			}else{
				var json=eval("("+result+")");
				pageArr[thisId+"_"+nextPage]=json;
				thisPage=nextPage;				
			}
		}else thisPage=nextPage;
		if(thisPage==nextPage){
			$("#pre").removeAttr("disabled");
			showData(thisId+"_"+thisPage);
		}	
	});
	$("#pre").click(function(){
		var thisId=$("#classid").val();
		var prePage=thisPage-1;
		if(pageArr[thisId+"_"+prePage]==null){
			var result=getAction(<?=Mini::AJAX_GET?>,{op:"getpagelist",classid:thisId,pageindex:prePage,pagesize:maxSize},"获取栏目数据");
			if(result==null){
				pageArr[thisId+"_"+prePage]=null;
				$("#pre").attr("disabled","disabled");			
				showMsg("没有上一页！","没有上一页！");				
			}else{
				var json=eval("("+result+")");
				pageArr[thisId+"_"+prePage]=json;
				thisPage=prePage;				
			}
		}else thisPage=prePage;
		if(thisPage==prePage){
			$("#next").removeAttr("disabled");
			showData(thisId+"_"+thisPage);			
		}				
	});
});
function showData(key){
	var cname=$("#classid option:selected").text();
	var str='';
	if(pageArr[key]==null){
		noplay();
		$(".msg").html("栏目["+cname+"]暂无数据或无法获取数据");
		return false;
	}
	if(pageArr[key].length==maxSize) $("#next").removeAttr("disabled");
	for ( var i in pageArr[key]) {
		str+='<tr><td align="center">'+pageArr[key][i].pageid+'</td><td align="center"><a href="'+pageArr[key][i].pageurl+pageArr[key][i].filename+'.html">'+pageArr[key][i].title+'</a></td><td align="center">'+pageArr[key][i].username+'</td><td align="center">暂无</td><td align="center"><a href="update.php?pageid='+pageArr[key][i].pageid+'">修改</a>&nbsp;<a href="delete.php?pageid='+pageArr[key][i].pageid+'">删除</a></td></tr>';		
	}
	$("#pagelist").html(thead+str+tfoot);
	$(".msg").html("获取栏目["+cname+"]数据成功");		
}
function noplay(){
	$("#pagelist").html(thead+tnull+tfoot);
	$("#pre").attr("disabled","disabled");
	$("#next").attr("disabled","disabled");	
}

</script>
</body>
</html>